<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>地图初始加载定位到当前城市</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main.css?v=1.0" />
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.1&key=8e3db2ff2ff33fe03f5b952ed07de5cd&plugin=AMap.Geocoder"></script>
    <style type="text/css">
   
    </style>
</head>

<body>
    <div id="mapContainer"></div>
</body>

</html>
<script src="../js/gaode_map.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	// 获取定位信息
	eflower_location={
				success:function(date){},
				error:null,
				GdMapload:function(){
					var Lbody = document.body;
				 	var LO = document.createElement("div");
				 			LO.style.display='none';
				 	    LO.setAttribute('id', 'ContentMap');
				 	    Lbody.appendChild(LO);
				   },
				Gdlocation:function(_success){
					if(_success != undefined && typeof(_success) == "function"){
						eflower_location.success=_success;
					}
					
					eflower_location.GdMapload();
					var lnglatXY=new Array();
					map = new AMap.Map('container');
					map.plugin('AMap.Geolocation', function() {
					    geolocation = new AMap.Geolocation({
					        enableHighAccuracy: true,//是否使用高精度定位，默认:true
					        timeout: 10000,          //超过10秒后停止定位，默认：无穷大
					      });
					    map.addControl(geolocation);
					    geolocation.getCurrentPosition();
					    AMap.event.addListener(geolocation, 'complete',eflower_location.onComplete);//返回定位信息
					    AMap.event.addListener(geolocation, 'error', eflower_location.onError);      //返回定位出错信息
					});
				},
			    onComplete:function(data){
			      	eflower_location.success(data);
					  },
					  onError:function(data){
						  	if(eflower_location.error !=null && typeof(eflower_location.error) == "function"){
						  		eflower_location.error(data);
						  	}else{
						  			console.error("error");
						  			return;
						  	}
			 	}
	}

   	eflower_location.Gdlocation(function(data){
		 alert(data.position.getLng()+" "+data.position.getLat());
		 lnglatXY = [data.position.getLng(), data.position.getLat()]; //已知点坐标
	    function regeocoder() {  //逆地理编码
	        var geocoder = new AMap.Geocoder({
	            radius: 1000,
	            extensions: "all"
	        });        
	        content.log(lnglatXY)
	        geocoder.getAddress(lnglatXY, function(status, result) {
	            if (status === 'complete' && result.info === 'OK') {
	                geocoder_CallBack(result);
	            }
	        });        
	        var marker = new AMap.Marker({  //加点
	            map: map,
	            position: lnglatXY
	        });
	        map.setFitView();
	    }
	    function geocoder_CallBack(data) {
	        var address = data.regeocode.formattedAddress; //返回地址描述
	        console.log(address);
	    }

		
	});

	


    //初始化地图对象，加载地图
    // var map = new AMap.Map('mapContainer', {
    //     resizeEnable: true
    // });
    // console.log(map)
   




</script>